package details.controller;

import config.Interceptor.PassToken;
import controller.BaseController;
import details.entity.Wxuserdetails;
import details.service.impl.Userdetailsserviceimpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.CommonRetumType;


@RestController
@RequestMapping("/details")
public class Userdetailscontroller{
    @Autowired
    Userdetailsserviceimpl userdetailsserviceimpl;


    @PassToken
    @GetMapping("/create")
    public CommonRetumType create(Wxuserdetails wxuserdetails)
    {

        return CommonRetumType.create(userdetailsserviceimpl.insertSelective(wxuserdetails),"用户信息添加成功");
    }

    @PassToken
    @GetMapping("/read")
    public CommonRetumType read(@RequestParam("openId") String openid)
    {
         Wxuserdetails wxuserdetails = userdetailsserviceimpl.selectOpenid(openid);

        return CommonRetumType.create(wxuserdetails,"用户信息读取成功");
    }

    @PassToken
    @GetMapping("/index")
    public CommonRetumType index()
    {
        return CommonRetumType.create("null","null");
    }

    @PassToken
    @PostMapping("/update")
    public CommonRetumType update(@RequestBody @RequestParam(value = "username",required = false) String username,
                                  @RequestParam(value = "usersex",required = false) String usersex,
                                  @RequestParam(value = "userage",required = false) Integer userage,
                                  @RequestParam(value = "userbirthday",required = false) String userbirthday,
                                  @RequestParam(value = "userweight",required = false) String userweight,
                                  @RequestParam(value = "userheight",required = false) String userheight,
                                  @RequestParam(value = "userconstellation",required = false) String userconstellation,
                                  @RequestParam(value = "usersignature",required = false)String usersignature,
                                  @RequestParam(value = "useraddress",required = false) String useraddress,
                                  @RequestParam(value = "openid",required = false) String openid)
    {
        Wxuserdetails wxuserdetails = new Wxuserdetails();
        wxuserdetails.setUsername(username);
        wxuserdetails.setUsersex(usersex);
        wxuserdetails.setUserbirthday(userbirthday);
        wxuserdetails.setUserage(userage);
        wxuserdetails.setUserweight(userweight);
        wxuserdetails.setUserheight(userheight);
        wxuserdetails.setUserconstellation(userconstellation);
        wxuserdetails.setUsersignature(usersignature);
        wxuserdetails.setUseraddress(useraddress);
        wxuserdetails.setOpenId(openid);
        return CommonRetumType.create(userdetailsserviceimpl.updateByPrimaryKeySelective(wxuserdetails),"用户信息更新成功");
    }

    @PassToken
    @DeleteMapping("/delete")
    public CommonRetumType delete(Integer id)
    {
        return CommonRetumType.create(userdetailsserviceimpl.deleteByPrimaryKey(id),"用户信息删除成功");
    }

    @PassToken
    @GetMapping("/updatecount")
    public CommonRetumType updatecount()
    {
        return CommonRetumType.create(userdetailsserviceimpl.updatecount(),"更新成功");
    }
}
